#ifndef IMPRESSIONIST_H
#define IMPRESSIONIST_H
#define SAMPLE_SOLUTION
#include <stdio.h>

#include <FL/Fl.h>
#include <FL/gl.h>
#include <GL/glu.h>
#include <Eigenvalues>
#include <vector>
#include "config.h"
#include "Bitmap.h"
#include "vector.h"
#include "Point.h"

#define TRUE	1
#define FALSE	0

#ifdef WIN32
#define M_PI	3.1415926535F
#endif

using namespace std;
using namespace Eigen;

class ImpressionistUI;

class Impressionist{
public:
	Impressionist();
	int pnpoly(int nvert, double *vertx, double *verty, double testx, double testy);
	//int loadAndCalculateLines(char *fname);
	void calculateHomography();
	void calculatePatches();
	void calculateVanishingPoints();
	void calculateRealPosition(Point point, Point ground_point);

	//UI functions
	void setUI(ImpressionistUI* ui);
	int loadImage(char *fname) ;
	bool in_valid_range(int j, int i);
	void refresh();

public:
	ImpressionistUI* m_pUI;

	//(@-p-@)
	int			width, height;	// width and height of the picture
	//MyVector3d	points[12];	// line endpoints
	//MyVector3d	lines[6];	// line parameters
	//MyVector3d	vpoints[3];	// vanishing points
	//MyVector3d	lxy;		// vanishing line of the X-Y plane

	vector<pair<Vector3d,Vector3d> > lines[3]; // lines parallel to x , y or z axis
	Vector3d vpoints[3]; // vanishing points for x, y, z direction
	Vector3d l_xy;		// vanishing line for x y direction

	// for reference plane
	double p_x[4],p_y[4]; // four reference points in the real plane
	double pp_x[4],pp_y[4]; // four reference points in the image plane

	Matrix3d ground_homo;
	vector<Vector3i> real_positions;

	// for patches;
	int total_patch;
	vector<double*>	patch_p_x; // for texture points in the real plane
	vector<double*>	patch_p_y;
	vector<double*>	patch_pp_x; // for texture points in the image plane
	vector<double*>	patch_pp_y;
	
	// point location related to the height
	double t_x, t_y;	// point out of ground plane on image plane
	double b_x, b_y;	// point correspondingly on the ground plane on image plane
	double r_x, r_y, r_z; // real position in 3d

	MyVector3d	scene[4];	// origin and X, Y, Z vector form origin
	double		alpha[3];	// scaling factor for X, Y, Z direction
	MyVector3d	positions3d;
	double alpha_z;

	//handles drawing
	unsigned char* picture;
	double			m_scale;
};

#endif